﻿using IntelligentAgriculture.Contracts.Interface.EarTagService;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.Services.Management;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.ColumnManageCommandJamdler
{
    public class EarTageDelRangeCommandHandler : IRequestHandler<EarTageDelRangeCommand, Results<int>>
    {
        private readonly IEarTageService _iearTageService;

        public EarTageDelRangeCommandHandler(IEarTageService iearTageService)
        {
            _iearTageService = iearTageService;
        }
        /// <summary>
        /// 处理删除一批耳标命令的请求
        /// </summary>
        /// <param name="request">包含要删除的耳标ID列表的命令对象</param>
        /// <param name="cancellationToken">取消操作的取消标记</param>
        /// <returns>一个表示操作结果的异步任务，返回删除操作的结果</returns>
        public async Task<Results<int>> Handle(EarTageDelRangeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var list = await _iearTageService.DeleteRange(request.ids);
                return Results<int>.DataResult(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
